import { BasicColumn, FormSchema } from '@apps/antd-admin/src/components/Table';
import { weChatList } from '../../platformManage/wechat/data/api';
import { xunLianPayParamList } from '../xunlianPayparam/api';
import { yinLianPayParamList } from '../yinlianPayparam/api';

export const columns: BasicColumn[] = [
  {
    title: '公众号',
    dataIndex: 'weChatName',
    width: 200,
  },
  {
    title: '支付入口',
    dataIndex: 'entranceType',
    width: 200,
    customRender: ({ record }: Recordable) => {
      const entranceTypeArray = [
        { label: '微信支付N', value: 1 },
        { label: '微信支付Y', value: 2 },
      ];
      const entranceType: any = entranceTypeArray.find((item) => item.value == record.entranceType);
      if (entranceType) {
        return entranceType.label;
      }
      return '';
    },
  },
  {
    title: '支付渠道',
    dataIndex: 'payparamCode',
    width: 200,
    customRender: ({ record }: Recordable) => {
      const payParamCodeArray = [
        { label: '讯联支付', value: 'xunLian' },
        { label: '银联支付', value: 'yinLian' },
      ];
      const payParamCode: any = payParamCodeArray.find((item) => item.value == record.payparamCode);
      if (payParamCode) {
        return payParamCode.label;
      }
      return '';
    },
  },
  {
    title: '支付参数',
    dataIndex: 'payparamName',
    width: 200,
  },
  {
    title: '排序',
    dataIndex: 'payparamSort',
    width: 200,
  },
  {
    title: '备注',
    dataIndex: 'remark',
    width: 200,
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 200,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'weChatId',
    label: '公众号',
    component: 'ApiSelect',
    colProps: { span: 5 },
    componentProps: {
      api: weChatList,
      params: {},
      labelField: 'weChatName',
      valueField: 'weChatId',
      immediate: true,
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '主键',
    field: 'payconfigId',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    label: '公众号',
    field: 'weChatId',
    component: 'ApiSelect',
    required: true,
    componentProps: {
      api: weChatList,
      params: {},
      labelField: 'weChatName',
      valueField: 'weChatId',
      immediate: true,
    },
  },
  {
    label: '支付入口',
    field: 'entranceType',
    component: 'Select',
    required: true,
    componentProps: {
      options: [
        { label: '微信支付N', value: 1 },
        { label: '微信支付Y', value: 2 },
      ],
    },
  },
  {
    label: '支付渠道',
    field: 'payparamCode',
    component: 'Select',
    required: true,
    componentProps: ({ formModel }) => {
      return {
        options: [
          { label: '讯联支付', value: 'xunLian' },
          { label: '银联支付', value: 'yinLian' },
        ],
        onChange: (payparamCode) => {
          console.info('payparamCode', payparamCode);
          formModel.payparamId = null;
        },
      };
    },
  },
  {
    label: '支付参数',
    field: 'payparamId',
    component: 'ApiSelect',
    required: true,
    ifShow: ({ model }) => {
      if (model.payparamCode) {
        return true;
      } else {
        return false;
      }
    },
    componentProps: ({ formModel }) => {
      let payparamCode = formModel.payparamCode;
      console.info('formModel.payparamCode', payparamCode);
      if (payparamCode == 'xunLian') {
        console.info('xunLian');
        return {
          api: xunLianPayParamList,
          labelField: 'paramName',
          valueField: 'xunlianPayparamId',
          showSearch: true,
          immediate: true,
        };
      } else {
        return {
          api: yinLianPayParamList,
          labelField: 'yinlianPayName',
          valueField: 'yinlianPayparamId',
          showSearch: true,
          immediate: true,
        };
      }
    },
  },
  {
    label: '排序',
    field: 'payparamSort',
    component: 'InputNumber',
    required: true,
  },
  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
  },
];
